import time

from selenium.webdriver.common.by import By
from pom.base_page import BasePage


class MarketManagePage(BasePage):
    def data_store(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[1]/a/li/span').click()
        time.sleep(3)
        catalogue = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[3]/div').text
        department = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[4]/div').text
        shared_address = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[5]/div').text
        print(catalogue, department, shared_address, "***********************")

        assert catalogue == "大大怪集团"
        assert department == "柠檬"
        assert shared_address == "localhost"

        # 分页功能是否正常
        self.driver.find_element(By.CLASS_NAME, "btn-next").click()
        time.sleep(2)
        t_name = self.driver.find_element(By.XPATH, "//div[2]//div[2]/div[3]//tr/td[3]/div").text
        t_department = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div[2]/div[3]//tr/td[4]/div').text

        assert t_name == "生态环境局"
        assert t_department == "生态环境局"

        # search
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[1]/div/div/input').send_keys("http")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[2]/div/div/input').send_keys("气象局")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[4]/div/button[1]').click()

        time.sleep(2)
        s_catalogue = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[3]/div').text
        s_department = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[4]/div').text
        s_shared_address = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[5]/div').text
        print(s_catalogue, s_department, s_shared_address, "***********************")

        assert s_catalogue == "气象局"
        assert s_department == "气象局"
        assert s_shared_address == "http://10.14.216.215:8081/api/resource/findAll"

        # 增加删除功能
        # self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[1]/button').click()
        # time.sleep(2)
        # prompt = self.driver.switch_to.alert
        # prompt.send_keys("asxcsaxas")
        # cata_name = "大大怪集团"
        # dept_name = "纳木错"
        # share_addr = "aka:8008"
        # self.driver.find_element(By.XPATH, '//div[5]/div/div[2]/form/div[1]/div/div/input').send_keys(cata_name)
        # self.driver.find_element(By.XPATH, '//div[5]/div/div[2]/form/div[2]/div/div/input').send_keys(dept_name)
        # self.driver.find_element(By.XPATH, '//div[5]/div/div[2]/form/div[3]/div/div/input').send_keys(share_addr)
        # self.driver.find_element(By.XPATH, '//div[5]/div/div[3]/div/button[1]/span').click()

    def server_store(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[2]/a/li/span').click()
        time.sleep(3)
        chinese_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text
        english_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[5]/div').text

        assert chinese_name == "分页获取所有数据资源"
        assert english_name == "sfgsfdgsfdg"

        print(chinese_name, english_name, "*******************")

    def customized_shop(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[3]/a/li/span').click()

        time.sleep(2)
        serve_id = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        custom_theme = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[8]/div').text

        assert serve_id == "1"
        assert custom_theme == "测试定制"

        print(serve_id, custom_theme, "*******************")

    def typical_applications(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[4]/a/li/span').click()

        time.sleep(2)
        category = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        custom_form = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text

        assert category == "API应用"
        assert custom_form == "自定义"

        print(category, custom_form, "*******************")

        # 翻页
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[3]/div/button[2]').click()

        time.sleep(2)
        t_category = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        t_custom_form = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text

        assert t_category == "普通应用"
        assert t_custom_form == "自定义"

        # search
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[1]/div/div/input').send_keys("注册应用12")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[2]/div/div/input').send_keys("registerApps")
        self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/section/div/form/div[5]/div/button[1]').click()

        time.sleep(1)
        # ===================
        # ===搜索测试未完成 ===
        # ===================

    def package_manage(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[5]/a/li/span').click()

        time.sleep(2)

    def service_charge(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[6]/a/li/span').click()

        time.sleep(2)
        spec_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        goods_type = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text

        assert spec_name == "88"
        assert goods_type == "服务商店"

        print(spec_name, goods_type, "*******************")

        # search
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[1]/div/div/input').send_keys("500")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/form/div[4]/div/button[1]').click()

        time.sleep(2)
        s_spec_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        s_goods_type = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text

        assert s_spec_name == "500次"
        assert s_goods_type == "服务商店"

    def service_control(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[7]/a/li/span').click()

        time.sleep(2)
        user_type = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        user_level = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text

        assert user_type == "0"
        assert user_level == "0"

        print(user_type, user_level, "*******************")

    def service_catalog(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[8]/a/li/span').click()

        time.sleep(2)

    def service_test(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[9]/a/li/span').click()

        time.sleep(2)

    def service_trial(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[10]/a/li/span').click()

        time.sleep(2)

    def service_category(self):
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[11]/a/li/span').click()

        time.sleep(2)
